<?PHP 
include_once 'setup/setup.php';

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.2.0/build/reset-fonts-grids/reset-fonts-grids.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.3.0/build/base/base-min.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>教育新聞</title>
</head>

<body>
<h2>教育新聞</h2>
<table width="80%" border="1" align="center">
  <tr>
    <td width="6%" bgcolor="#FFFF99">編號</td>
    <td width="78%" bgcolor="#FFFF99">主旨</td>
    <td width="16%" bgcolor="#FFFF99">日期</td>
  </tr>
  <?php 
	$query=sprintf("SELECT count(*) FROM edu_news");
	$total = $db->get_var($query);				
    if($_GET['p']==0)$_GET['p']=1;									
		$page_count=ceil($total/$READ_NUM);
	if($_GET['p']==1)
		$start_num=0;
	else
 		$start_num=($_GET['p']-1)*$READ_NUM;  
  
  
  	$query=sprintf("SELECT * FROM edu_news ORDER BY e_id DESC LIMIT %d,%d",$start_num,$READ_NUM);
	$con = $db->get_results($query);

	if(!$con){
  ?>
  <tr>
    <td colspan="3" align="center">目前沒有資料</td>
  </tr>
  <?php 
  	}else{
		foreach($con as $cont){
  ?>
  <tr>
    <td><?php echo $cont->e_id;?></td>
    <td align="left"><a href="view.php?g=<?php echo $cont->e_id; ?>"><?php echo $cont->e_title;?></a>(<?PHP echo $cont->e_hits; ?>)</td>
    <td nowrap="nowrap"><?php echo $cont->e_date;?></td>
  </tr>
  <?PHP
  		}//foreach
	}//if end
  ?>
  <tr>
    <td colspan="3" bgcolor="#FFFFFF"> 
	<?php 
 /* 顯示分頁 */
if($_GET['p']!=1) printf("<a href='%s?p=%d'> 【上一頁】</a>",$_SERVER['PHP_SELF'],$_GET['p']-1);
for($i=1;$i<=$page_count;$i++)
{
	echo " <a href='$_SERVER[PHP_SELF]?p=$i'>$i</a> ";	
}											
if($_GET['p']<$page_count) printf("<a href='%s?p=%d'>【下一頁】</a>",$_SERVER['PHP_SELF'],$_GET['p']+1);
?></td>
  </tr>
</table>
<a href="register.php">我要訂閱電子報</a><br />
<a href="login.php">管理介面
</a>
</body>
</html>

